package com.xtedu.examproject.util;

import jakarta.servlet.ServletContext;

import java.util.concurrent.atomic.AtomicInteger;

public class VisitCounter {
    private static final String COUNTER_KEY = "visitCount";
    public static void incrementVisitCounter(ServletContext context) {
        AtomicInteger counter = (AtomicInteger) context.getAttribute(COUNTER_KEY);
        if (counter == null) {
            counter = new AtomicInteger(0);
            context.setAttribute(COUNTER_KEY, counter);
        }
        counter.incrementAndGet();
    }

    public static int getVisitCount(ServletContext context) {
        AtomicInteger counter = (AtomicInteger) context.getAttribute(COUNTER_KEY);
        return counter == null ? 0 : counter.get();
    }






}
